﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace HWCDNLogAnalysis
{
    public partial class frmHWCDNSetting : Form
    {
        //获取Configuration对象
        System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        public frmHWCDNSetting()
        {
            InitializeComponent();
        }

        private void frmHWCDNSetting_Load(object sender, EventArgs e)
        {
            txtAK.Text = config.AppSettings.Settings["HWCloud:AK"].Value;
            txtSK.Text = config.AppSettings.Settings["HWCloud:SK"].Value;
            txtCropId.Text = config.AppSettings.Settings["HWCloud:CropId"].Value;
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            //config.AppSettings.Settings["HWCloud:AK"].Value=txtAK.Text;
            //config.AppSettings.Settings["HWCloud:SK"].Value= txtSK.Text;
            //config.AppSettings.Settings["HWCloud:CropId"].Value=txtCropId.Text;
            //config.Save(ConfigurationSaveMode.Modified);
            //ConfigurationManager.RefreshSection("appSettings");
            var dic=new Dictionary<string, string>();
            dic["HWCloud:AK"]=txtAK.Text;
            dic["HWCloud:SK"] = txtSK.Text;
            dic["HWCloud:CropId"] = txtCropId.Text;
            FunUtils.AddConfig(dic, true);
            MessageBox.Show("设置AK/SK值成功");
            this.DialogResult = DialogResult.OK;
            this.Close();
        }
    }
}
